import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { IToolTipItem } from "../../../../com/mui/manager/IToolTipItem";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { FriendStyle } from "./FriendStyle";
import { IntimateHeartShaped } from "./item/IntimateHeartShaped";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { Language } from "../../../../extend/language/Language";
import { FriendInfo } from "../../model/FriendInfo";
import { EFriendFlag } from "../../../../Message/Game/EFriendFlag";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
import { PlayerOpMenuConst } from "../common/menu/PlayerOpMenuConst";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { ImageInfo } from "../../../../com/gengine/resource/info/ImageInfo";
import { AvatarInfo } from "../../resource/info/AvatarInfo";
import { AvatarType } from "../../resource/info/AvatarType";
import { LoaderManager } from "../../../../com/gengine/resource/LoaderManager";
import { LevelLimitDefin } from "../../../common/defin/LevelLimitDefin";
import { Cache } from "../../cache/Cache";
import { MsgManager } from "../../manager/MsgManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ToolTipsManager } from "../../../../com/mui/manager/ToolTipsManager";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
//class FriendCellRenderer2
    
    export  class FriendCellRenderer2 extends CellRenderer implements IToolTipItem
    {
        constructor()
        {
            super();
            this.width = 180;
            this.initStyles();
            this.create();
            this.mouseChildren = true;
            return;
        }

        /* internal  */initStyles(): void
        {
            this.setStyle("downSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("overSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("selectedOverSkin", GlobalClass.getBitmap("Friend_over"));
            this.setStyle("selectedUpSkin", GlobalClass.getBitmap("Friend_over"));
            return;
        }

        /* internal  */create(): void
        {
            this._headImage = new Object /* flash.display.Bitmap */();
            this._headImage.width = 20;
            this._headImage.height = 20;
            this._headImage.y = 7;
            this.addChild(this._headImage);
            this._textName = new Object /* flash.text.TextField */();
            this._textName.x = 25;
            this._textName.width = 90;
            this._textName.height = 20;
            this._textName.mouseEnabled = false;
            this._textName.filters = [FilterConst.nameGlowFilter];
            this._textName.defaultTextFormat = FriendStyle.textFormatOnLine;
            this.addChild(this._textName);
            this._textCamp = new Object /* flash.text.TextField */();
            this._textCamp.x = 115;
            this._textCamp.width = 40;
            this._textCamp.height = 20;
            this._textCamp.mouseEnabled = false;
            this._textCamp.filters = [FilterConst.nameGlowFilter];
            this._textCamp.defaultTextFormat = FriendStyle.textFormatOnLine;
            this.addChild(this._textCamp);
            this._intimateHeartShaped = new IntimateHeartShaped();
            this._intimateHeartShaped.x = 27;
            this._intimateHeartShaped.y = 20;
            this._intimateHeartShaped.mouseEnabled = false;
            this._intimateHeartShaped.mouseChildren = false;
            this.addChild(this._intimateHeartShaped);
            this._spTip = new Object /* flash.display.Sprite */();
            this._spTip.graphics.beginFill(16777215, 0.01);
            this._spTip.graphics.drawRect(0, 0, 160, 32);
            this._spTip.graphics.endFill();
            this._spTip.doubleClickEnabled = true;
            this._spTip.cacheAsBitmap = true;
            this.addChild(this._spTip);
            this._btnBless = ObjCreate.createGLoadedButton(ResFileConst.cornucopiaBtn, 150, 3, 26, 19, this);
            this._btnBless.toolTipData = "<font color = \'#ffffff\'>" + Language.getString(40354) + "</font>";
            this.configListeners();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            if (typeof arg1 === "friendinfo") 
            {
                this._friendInfo = arg1 as FriendInfo;
                var loc1=this._friendInfo.friendFlag;
                switch (loc1) 
                {
                    case EFriendFlag._EFriendFlagFriend:
                    {
                        PlayerOpRegister.Register(this, this._friendInfo.friendPlayerInfo, PlayerOpMenuConst.FriendOpMenu, this._friendInfo);
                        break;
                    }
                    case EFriendFlag._EFriendFlagEnemy:
                    {
                        PlayerOpRegister.Register(this, this._friendInfo.friendPlayerInfo, PlayerOpMenuConst.EnemyOpMenu, this._friendInfo);
                        break;
                    }
                    case EFriendFlag._EFriendFlagBlackList:
                    {
                        PlayerOpRegister.Register(this, this._friendInfo.friendPlayerInfo, PlayerOpMenuConst.BlackListOpMenu, this._friendInfo);
                        break;
                    }
                }
                this.refresh();
            }
            return;
        }

        public /* override */ set label(arg1: string)
        {
            return;
        }

        public removeBtnBless(): void
        {
            DisplayUtil.removeMe(this._btnBless);
            return;
        }

        protected refresh(): void
        {
            var imgName: string;
            var loadCompl: Function;

            var loc1;
            loadCompl = null;
            loadCompl = (arg1: ImageInfo): void
            {
                _headImage.bitmapData = arg1.bitmapData;
                _headImage.width = 20;
                _headImage.height = 20;
                _headImage.y = 7;
                return;
            }
            imgName = AvatarInfo.getPlayerAvatarName(this._friendInfo.friendPlayerInfo.camp, this._friendInfo.friendPlayerInfo.sex, AvatarType.FRIEND, this._friendInfo.friendPlayerInfo.avatarId);
            if (this._friendInfo.friendPlayerInfo.photo) 
            {
                AvatarInfo.getUpdateAvatar(this._friendInfo.friendPlayerInfo.entityId, AvatarType.UPLOADSMALL, loadCompl);
            }
            else 
            {
                LoaderManager.instance.load(imgName, loadCompl);
            }
            this._textName.text = this._friendInfo.friendPlayerInfo.playerName;
            this._textCamp.text = this._friendInfo.friendPlayerInfo.campName;
            this._intimateHeartShaped.intimate = this._friendInfo.intimate;
            if (this._friendInfo.friendPlayerInfo.online) 
            {
                this._headImage.filters = [];
                if (this._friendInfo.friendPlayerInfo.isVIP) 
                {
                    this._textName.setTextFormat(FriendStyle.textFormatVIPOnline);
                    this._textCamp.setTextFormat(FriendStyle.textFormatVIPOnline);
                    this._textName.filters = [FilterConst.vipGlowFilter];
                    this._textCamp.filters = [FilterConst.vipGlowFilter];
                }
                else 
                {
                    this._textName.setTextFormat(FriendStyle.textFormatOnLine);
                    this._textCamp.setTextFormat(FriendStyle.textFormatOnLine);
                    this._textName.filters = [FilterConst.nameGlowFilter];
                    this._textCamp.filters = [FilterConst.nameGlowFilter];
                }
            }
            else 
            {
                this._headImage.filters = [FilterConst.colorFilter];
                this._textName.setTextFormat(FriendStyle.textFormatOffline);
                this._textCamp.setTextFormat(FriendStyle.textFormatOffline);
                this._textName.filters = [FilterConst.nameGlowFilter];
                this._textCamp.filters = [FilterConst.nameGlowFilter];
            }
            this._btnBless.visible = this._friendInfo.friendPlayerInfo.online && this._friendInfo.friendPlayerInfo.level >= LevelLimitDefin.CornucopiaMinLevel && Cache.instance.role.entityInfo.level >= LevelLimitDefin.CornucopiaMinLevel;
            this._btnBless.enabled = !this._friendInfo.isCornucopiaed();
            this._btnBless.drawNow();
            this.setToolTipData();
            return;
        }

        /* internal  */configListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.dblClickHandler);
            this._btnBless.addEventListener(flash.events.MouseEvent.CLICK, this.onSendBless);
            return;
        }

        /* internal  */dblClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._friendInfo.friendFlag != EFriendFlag._EFriendFlagBlackList) 
            {
                if (this._friendInfo.friendPlayerInfo.online) 
                {
                    PlayerOpMenuConst.Opearte(PlayerOpMenuConst.ChatPirvate, this._friendInfo.friendPlayerInfo, this._friendInfo);
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(40353));
                }
            }
            PlayerOpRegister.HideOpList();
            return;
        }

        /* internal  */onSendBless(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CornucopiaBlessToFriend, this._friendInfo.friendPlayerInfo.entityId.id));
            arg1.stopPropagation();
            return;
        }

        /* internal  */setToolTipData(): void
        {
            var loc1="<textFormat leading=\'4\'>" + HTMLUtil.addColor(Language.getString(40355), GlobalStyle.color2) + HTMLUtil.addColor(this._friendInfo.friendPlayerInfo.level.toString(), GlobalStyle.color1) + "<br>" + HTMLUtil.addColor(Language.getString(40356), GlobalStyle.color2) + HTMLUtil.addColor(this._friendInfo.friendPlayerInfo.careerEnableName, GlobalStyle.color1) + "<br>" + HTMLUtil.addColor(Language.getString(40357), GlobalStyle.color2) + HTMLUtil.addColor(this._friendInfo.intimate.toString(), GlobalStyle.color1) + "<br>" + HTMLUtil.addColor(Language.getString(40358), GlobalStyle.color2) + HTMLUtil.addColor(this._friendInfo.initmateName, GlobalStyle.color1) + "<textFormat>";
            ToolTipsManager.unregister(this._spTip);
            ToolTipsManager.register(this._spTip, null, loc1);
            return;
        }

        public get toolTipData()
        {
            return this._toolTipData;
        }

        public set toolTipData(arg1)
        {
            if (arg1 == null || arg1 == "") 
            {
                ToolTipsManager.unregister(this);
            }
            else 
            {
                ToolTipsManager.register(this);
            }
            this._toolTipData = arg1;
            return;
        }

        protected /* var */_friendInfo: FriendInfo;

        /* internal */ /* var */_headImage: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_textName: Object /* flash.text.TextField */;

        /* internal */ /* var */_textCamp: Object /* flash.text.TextField */;

        /* internal */ /* var */_intimateHeartShaped: IntimateHeartShaped;

        /* internal */ /* var */_btnBless: GLoadedButton;

        /* internal */ /* var */_spTip: Object /* flash.display.Sprite */;

        /* internal */ /* var */_toolTipData;
    }
